// 方式一
// 一次扫描
// 时间：88ms - 49.35%
function sortColors(nums) {
  let start = 0;
  let total = 0;
  const len = nums.length;
  while (total < len) {
    total++;
    const ele = nums[start];
    if (ele === 0) {
      const [splice] = nums.splice(start, 1);
      nums.unshift(splice);
      start++;
    } else if (ele === 2) {
      const [splice] = nums.splice(start, 1);
      nums.push(splice);
    } else {
      start++;
    }
  }
  return nums;
}
console.log(sortColors([2, 0, 1, 2, 0]));
